package cn.com.blueInfo.core.baseService.init;

import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.CommandLineRunner;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

/**
 * 数据初始化
 */
@Log4j2
//@Component
@EnableScheduling
public class DataInitializer implements CommandLineRunner {

    private String currentIp01 = "";

    private String currentIp02 = "";

    private static final long FIVE = 5 * 1000;

    private static final long ONE = 1000;

    @Override
    public void run(String... args) throws Exception {
        log.info("定时任务启动了");
    }

    @Scheduled(fixedRate = FIVE)
    public void timerTask01() {
        if (StringUtils.isEmpty(currentIp02)) {
            currentIp01 = "suxch01";
            log.info("已将当前IP地址设置为：" + currentIp01);
        } else {
            log.info("当前IP地址是：" + currentIp01);
        }
    }

    @Scheduled(fixedRate = ONE)
    public void timerTask02() {
        if (StringUtils.isEmpty(currentIp01)) {
            currentIp02 = "suxch02";
            log.info("已将当前IP地址设置为：" + currentIp02);
        } else {
            log.info("当前IP地址是：" + currentIp02);
        }
    }

}
